/*
 * @Author: 张帆 zhangfan@jxtech.net
 * @Date: 2023-12-20 14:59:49
 * @LastEditors: 张帆 zhangfan@jxtech.net
 * @LastEditTime: 2024-07-11 15:03:27
 * @FilePath: /qiankun/qiankun-micro-vue3-app3/src/main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import './public-path.js'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'

// @ts-ignore
let instance = null

// @ts-ignore
function render(props = {}) {
    console.log('props===', props)
    // @ts-ignore
    const { container } = props;

    // 注释的部分是vue2的例子
    // router = new VueRouter({
    //   base: window.__POWERED_BY_QIANKUN__ ? '/app-vue/' : '/',
    //   mode: 'history',
    //   routes,
    // });
  
    // instance = new Vue({
    //   router,
    //   store,
    //   render: (h) => h(App),
    // }).$mount(container ? container.querySelector('#app') : '#app');

    // 这个是vue3的例子
    instance = createApp(App)
    instance.use(router)
    instance.mount(container ? container.querySelector('#app') : '#app')
}

// 独立运行时
// @ts-ignore
if (!window.__POWERED_BY_QIANKUN__) {
    render();
}

export async function bootstrap() {
    console.log('[vue] vue app bootstraped==');
}
// @ts-ignore
export async function mount(props) {
    console.log('[vue] props from main framework==', props);
    render(props);
    // 以下代码是视频中的
    // instance.config.globalProperties.$onGlobalStateChange = props.onGlobalStateChange
    // instance.config.globalProperties.$setGlobalState = props.setGlobalState
}
export async function unmount() {
    // @ts-ignore
    instance.$destroy()
    // @ts-ignore
    instance.$el.innerHTML = ''
    instance = null
}


// createApp(App).mount('#app')
